home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
aminet
/
mus
/
play
/
multiplsr.lha
/
progwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-14
|
9KB
|
474 lines
/*
* MultiPlayer
* Copyright (C) 1992 Bryan Ford
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* I (the author of MultiPlayer) can be contacted on the Internet at
* "bryan.ford@m.cc.utah.edu". See "Player.doc" for other addresses.
*
* $Id: progwin.c,v 4.5 92/07/19 22:16:52 BAF Exp $
*
* $Log: progwin.c,v $
* Revision 4.5 92/07/19 22:16:52 BAF
* Calling format for progload() and progsave() changed
* Fixed nasty progwin hanging bug
*
* Revision 4.4 92/07/19 18:09:13 BAF
* Adjustment for putting localdata back into RemindNodes
* Made load/save GuidoRequester calls run off the DoList
*
* Revision 4.3 92/07/12 08:27:37 BAF
* end() waits with an EasyRequester as necessary until font requester comes down
*
* Revision 4.2 92/06/21 11:13:04 BAF
* Migrated regargs to stdargs
*
* Revision 4.1 92/06/06 19:56:14 BAF
* Major_code_cleanup
*
* Revision 3.2 92/05/25 08:24:48 BAF
* Got rid of some "please register" references I forgot about
*
* Revision 3.1 92/05/25 07:53:26 BAF
* GNU-ized.
*
*
*/
// System includes
#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/asl.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/wb.h>
#include "bry/macros.h"
#include "bry/remind.h"
#include "bry/misc.h"
#include "bry/guido.h"
#include "player.h"
extern GuidoSpec progwinspec, progwinfrspec;
extern short progwinleft;
struct Gadget *progwinlvgad;
static long check(long sigmask);
static long close(int remake);
static void init(void);
void progwinlistattach(void);
void progwinselmod(void);
static struct MPWin mpwin = {progwinspec,&progwinleft,init,
{0},{{0},check},{{0},close}};
static struct AppWindow *awin;
static long clicksecs, clickmics;
static void *ifr;
static char frsave;
static short lastsel = -1;
static struct ModNode *
findnode(int num)
{
struct ModNode *node = modlist.mlh_Head;
while(1)
{
if(!node->node.mln_Succ)
return(0L);
if(num-- <= 0)
return(node);
node = node->node.mln_Succ;
}
}
static void
getts(int *t,int *s)
{
struct ModNode *node = modlist.mlh_Head;
int num = 0;
while(1)
{
if(!node->node.mln_Succ)
{
num = -1;
break;
}
if(node == selmod)
break;
node = node->node.mln_Succ;
num++;
}
*s = num;
*t = *s-4;
if(*t < 0)
*t = 0;
}
void
progwinlistattach(void)
{
int t,s;
if(mpwin.win)
{
getts(&t,&s);
GAttachListView(mpwin.win,progwinlvgad,&modlist,t,lastsel = s);
}
}
void
progwinlistdetach(void)
{
if(mpwin.win)
GDetachListView(mpwin.win,progwinlvgad);
lastsel = -1;
}
void
progwinselmod(void)
{
int t,s;
if(mpwin.win)
{
getts(&t,&s);
if(lastsel != s)
GSetListViewActive(mpwin.win,progwinlvgad,t,lastsel = s);
}
}
static void
callback(struct GuidoMessage *im)
{
if(im->Class == IDCMP_RAWKEY)
windowkey(im->Code,PROGWINCONTEXT);
else if((im->Class == IDCMP_MOUSEBUTTONS) && (im->Code == MENUDOWN))
setfinmpwin(&mpwin);
}
static long
close(int remake)
{
if(awin)
{
RemoveAppWindow(awin);
awin = 0L;
}
closempwin(&mpwin);
if(remake)
showerr(openmpwin(&mpwin));
return(0);
}
static long
check(long sigmask)
{
if((sigmask & mpwin.sigmask) && GCheckPanel(mpwin.win,callback,0L))
setfinmpwin(&mpwin);
return(0);
}
void
gui_progwinlv(struct GuidoMessage *im)
{
struct ModNode *newmod;
newmod = findnode(lastsel = im->Code);
if(newmod)
{
if((newmod == selmod) && DoubleClick(clicksecs,clickmics,im->Seconds,im->Micros))
showerr(progact(selmod));
else
GlobSetLong(&selmod,newmod,progwinselmod),
clicksecs = im->Seconds, clickmics = im->Micros;
}
}
static void attach(void) {GlobPostMod(&modlist,0);}
static void detach(void) {GlobPreMod(&modlist,0);}
void
gui_progwintop(void)
{
if(selmod)
{
detach();
Remove(selmod);
AddHead(&modlist,selmod);
attach();
}
}
void
gui_progwinup(void)
{
struct ModNode *predpred;
if((selmod) && (predpred = selmod->node.mln_Pred->mln_Pred))
{
detach();
Remove(selmod);
Insert(&modlist,selmod,predpred);
attach();
}
}
void
gui_progwindown(void)
{
struct ModNode *succ;
if((selmod) && ((succ = selmod->node.mln_Succ)->node.mln_Succ))
{
detach();
Remove(selmod);
Insert(&modlist,selmod,succ);
attach();
}
}
void
gui_progwinbottom(void)
{
if(selmod)
{
detach();
Remove(selmod);
AddTail(&modlist,selmod);
attach();
}
}
void
gui_progwinadd(void)
{
showerr(reqmod(0));
}
void
gui_progwindel(void)
{
struct ModNode *delmod;
if(delmod = selmod)
{
if(delmod->node.mln_Succ->mln_Succ)
GlobSetLong(&selmod,delmod->node.mln_Succ,progwinselmod);
else if(delmod->node.mln_Pred->mln_Pred)
GlobSetLong(&selmod,delmod->node.mln_Pred,progwinselmod);
progdel(delmod);
}
}
void
gui_progwinclear(void)
{
progclear();
}
void
gui_progwinsort(void)
{
extern struct MinList modlist;
struct ModNode *n2, *n3;
char flag;
if((modlist.mlh_TailPred == (void*)&modlist) ||
(modlist.mlh_TailPred == modlist.mlh_Head))
return;
detach();
do
{ // A bubble sort...how efficient!
flag = 0;
for(n2 = modlist.mlh_Head;(n3 = n2->node.mln_Succ)->node.mln_Succ;)
{
if(stricmp(n2->nameptr,n3->nameptr) > 0)
{
Remove(n2);
Insert(&modlist,n2,n3);
flag = 1;
}
else
n2 = n3;
}
}
while(flag);
attach();
}
void
gui_progwinplay(void)
{
if(selmod)
showerr(progact(selmod));
}
void
gui_progwincurrent(void)
{
GlobSetLong(&selmod,curmod,0L);
}
static long
frcheck(void)
{
struct WBArg *args;
long count;
if(ifr && ((count = GCheckRequester(ifr,&args)) >= 0))
{
extern short progfrleft;
char *err;
GGetRequesterLocation(ifr,&progfrleft);
if(count > 0)
{
showerr(frsave ?
((err = progsave(args[0].wa_Lock,args[0].wa_Name)) ? err : "Program saved") :
progload(args[0].wa_Lock,args[0].wa_Name,1));
}
}
return(0);
}
static struct RemindNode frchecknode = {{0},frcheck};
static long
frend(void)
{
if(ifr)
{
while(GDeleteRequester(ifr))
{
static struct EasyStruct easy = {
sizeof(easy),0,"MultiPlayer","Please close all file and font requesters","OK"};
EasyRequestArgs(0,&easy,0,0);
}
ifr = 0L;
}
remind_rem(&frchecknode);
return(0);
}
static struct RemindNode frendnode = {{0},frend,0,-100};
static void
addfrcalls(void)
{
addcalls(&frchecknode,0,0,&frendnode);
}
/* Display the load/save-program requester (does not actually perform
the load or save - that comes later when the requester completes) */
static int
loadsave(int dummy,int save)
{
struct {
struct Window *win;
char *oktext;
int saveflag;
char *hailtext;
} parms;
int rc;
if(frsave = parms.saveflag = save)
parms.oktext = "Save", parms.hailtext = "Program to save";
else
parms.oktext = "Load", parms.hailtext = "Program to load";
parms.win = mpwin.win;
if(!ifr && !(ifr = GCreateRequester(progwinfrspec)))
showerr("File requester unavailable");
else
{
if((rc = GOpenRequester(ifr,progwinfrspec,&parms)) == 0)
showerr("File requester in use");
else if(rc < 0)
showerr("Not enough memory");
addfrcalls();
}
return(0);
}
void
gui_progwinload(void)
{
static struct RemindNode loadnode = {{0},loadsave,0};
adddo(&loadnode);
}
void
gui_progwinsave(void)
{
static struct RemindNode savenode = {{0},loadsave,1};
adddo(&savenode);
}
/* Routine called by openmpwin() for the program window*/
static void
init(void)
{
if(wbappport)
awin = AddAppWindowA(0,0,mpwin.win,wbappport,0);
progwinlistattach();
}
/* Toggle the program window, bounced from bouncekludge.asm */
char *
progwinopenclose(void)
{
if(mpwin.win)
{
setfinmpwin(&mpwin);
return(0L);
}
return(openmpwin(&mpwin));
}
void
gui_progwinopenclose(void)
{
showerr(progwinopenclose());
}